package easystudy.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import easystudy.dao.MemberDao;
import easystudy.dto.Member;

@Controller
public class MemberListController {
	
	private MemberDao memberDao;
	
	public void setMemberDao(MemberDao memberDao){
		this.memberDao = memberDao;
	}
	
	@RequestMapping(value="/member_list.ad")
	public ModelAndView doMemberListProcess(@RequestParam("page")int page){
		
		int size = 15;
		
		int count = memberDao.getMemberCount();
		
		int startRow = (page-1)*size+1;
		int endRow = startRow+size-1;
		
		List<Member> memberList = memberDao.getMemberList(startRow, endRow);
		
		int totalPageCount = (int)(count/size+0.95)+1;
		
		int start = ((int)(page/10))*10+1;
		int end = start+10-1;
		
		if(end>=totalPageCount)
			end=totalPageCount;
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("member_list");
		mav.addObject("memberList",memberList);
		mav.addObject("start", start);
		mav.addObject("end",end);
		mav.addObject("current",page);
		mav.addObject("maxpage",totalPageCount);
		return mav;
	}
	

}
